package com.lzx.iteam.adapter;

import android.content.Context;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.SalaryRuleEditBean;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2017年 01月 11日
 * Time: 下午4:37
 *
 * @QQ : 1234567890
 * **********************************
 */
public class SalaryRuleAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<SalaryRuleEditBean> mData;

    public SalaryRuleAdapter(Context mContext, ArrayList<SalaryRuleEditBean> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.salary_rule_item_layout,null);

        LinearLayout titleLayout = (LinearLayout) convertView.findViewById(R.id.ll_rule_title);
        TextView title = (TextView) convertView.findViewById(R.id.tv_rule_item_title);
        LinearLayout margin = (LinearLayout) convertView.findViewById(R.id.margin_rule_item);

        LinearLayout contentLayout = (LinearLayout) convertView.findViewById(R.id.ll_rule_item_content);
        TextView name = (TextView) convertView.findViewById(R.id.tv_rule_item_name);
        TextView about = (TextView) convertView.findViewById(R.id.tv_rule_item_about);
        EditText money = (EditText) convertView.findViewById(R.id.ed_rule_item);
        TextView unit1 = (TextView) convertView.findViewById(R.id.tv_rule_item_unit1);
        TextView unit2 = (TextView) convertView.findViewById(R.id.tv_rule_item_unit2);

        SalaryRuleEditBean bean = mData.get(position);

        int type = bean.getType();
        if (type == 0){
            titleLayout.setVisibility(View.GONE);
            contentLayout.setVisibility(View.VISIBLE);

            name.setText(bean.getName());
            about.setText(bean.getAbout());
            int unit = bean.getUnit();
            if (unit == 0){
                unit1.setText("每天");
                unit2.setText("元");
            }else if (unit == 1){
                unit1.setText("每次");
                unit2.setText("元");
            }else if (unit == 2){
                unit1.setText("日薪");
                unit2.setText("倍");
            }
            money.setText(StringUtil.floatFormat(bean.getMoney()));

        }else{
            titleLayout.setVisibility(View.VISIBLE);
            contentLayout.setVisibility(View.GONE);
            if (type == 1){
                title.setText("工资补贴");
                margin.setVisibility(View.GONE);
            }else {
                title.setText("工资扣款");
                margin.setVisibility(View.VISIBLE);
            }
        }
        Editable ea = money.getText();
        money.setSelection(ea.length());
        return convertView;
    }
}
